Virtual Cameras


How to make a virtual camera viewing system, by Stelios/Scoopex (stelios@vacuum.net)
HTML version by Azure.


Introduction

The following algorithms describe how to create a "virtual camera" viewing system in which you have a camera positioned anywhere in a 3D world pointing to an arbitrary focus point. Camera Z panning (roll) is also possible by defining a direction vector.


Equations

O = observer position (camera)
A = aimpoint position (focus)
R = direction point position (up)

N = normalize (Ax - Ox, Ay - Oy, Az - Oz)
D = normalize (Rx - Ox, Ry - Oy, Rz - Oz)
V = D - (D . N) * N
U = cross product (V,N)

			  | Ux Uy Uz |
View Matrix = | Vx Vy Vz |
			  | Nx Ny Nz |

Before rotating, you must translate all points so that their origin is point A ; after rotating you must translate the Z offsets using the distance from point O to A, ie. the length of the N vector before normalizing.

Note that "." means dot product and "*" means multiplying each component of the N vector with the dot product. (scalar / vector multiplication)

Hints

Final words

I use the above algorithms in my 3D engine and they work perfectly.

Thanks must go to Silver Eagle/Pygmy Projects, Celebrandil/Phenomena and Scout/C-Lous for their (kind) support.




Last change: Sunday, November 9th, 1997.
For questions referring to this pages content mail to: Stelios